/*
 * Copyright 2012 Alain Pannetrat (L1L1@gmx.com)
 * 
 * This file is part of cookie-miner.
 * 
 * cookie-miner is free software: you can redistribute it and/or modify 
 * it under the terms of the GNU General Public License as published by 
 * the Free Software Foundation, either version 3 of the License, or 
 * (at your option) any later version.
 * 
 * cookie-miner is distributed in the hope that it will be useful, but 
 * WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 
 * General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License 
 * along with cookie-miner. If not, see http://www.gnu.org/licenses/.
 *
 * @version: $Id$
 *
 */
#ifndef _URL_H_
#define _URL_H_

#include <string>
#include "common.h"
#include "keyvalue.h"

class URL { 
	public:
		static std::string entity_encode(const std::string& entity, const std::string& exceptions="");
		static std::string entity_decode(const std::string& entity);

		URL(const std::string& url="");
		bool decode(const std::string& url);
		std::string encode() const;
		std::string encode_relative() const;

		bool has_scheme() const {
			return _scheme.size(); }

		const std::string& scheme() const { 
			return _scheme; }

		bool has_username() const {
			return _username.size(); }

		const std::string& username() const {
			return _username; }

		bool has_password() const {
			return _password.size(); }
		
		const std::string& password() const {
			return _password; }

		bool has_domain() const {
			return _domain.size(); }
		
		const std::string& domain() const {
			return _domain; }

		bool has_port() const {
			return _port.size(); }
		
		const std::string& port() const {
			return _port; }

		bool has_path() const {
			return _path.size(); }
		
		const std::string& path() const {
			return _path; }

		bool has_query_string() const {
			return _query_string.size(); }
		
		std::string encode_query_string() const;
		
		const std::string& query_string_value(const std::string& key) const;

		bool query_string_value_defined(const std::string& key) const;

		KeyValueList::const_iterator query_string_begin() const {
			return _query_string.begin(); }

		KeyValueList::const_iterator query_string_end() const {
			return _query_string.end(); }
		
		bool has_fragment_id() const {
			return _fragment_id.size(); }

		const std::string& fragment_id() const {
			return _fragment_id; }

	private:
		bool parse_query_string_item(const std::string& item);

		std::string _scheme;
		std::string _username;
		std::string _password;
		std::string _domain;
		std::string _port;
		std::string _path;
		KeyValueList _query_string;
		std::string _fragment_id;
};

#endif

